package com.atguigu.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebFilter;
import jakarta.servlet.http.HttpFilter;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebFilter(urlPatterns = {"/delivery_system/*","/user/logout","/user/changepassword","/user/toPasswordPage","/delivery/*"})
public class LoginFilter extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
        Object attribute = request.getSession().getAttribute("user");
        if (attribute == null) {
            response.sendRedirect(request.getContextPath()+"/login.jsp");
        }else {
            chain.doFilter(request, response);
        }
    }
}
